package com.lxb.myforum.service

import java.util.Date

import com.lxb.myforum.base.BaseService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.stereotype.Service

import com.lxb.myforum.pojo.Reply
import com.lxb.myforum.repository.ReplyRepository
import com.lxb.myforum.service.spec.ReplySpec


@Service
class ReplyService @Autowired
constructor(private val replyRepository: ReplyRepository) : BaseService() {

    fun findRelies(reply: Reply, pageable: PageRequest): Page<Reply> {

        return replyRepository.findAll(ReplySpec(reply), pageable)
    }

    fun saveReply(reply: Reply): Reply {
        if (reply.id == null) {
            reply.createTime = Date()
        }
        reply.updateTime = Date() // 更新时间一直在变的
        return replyRepository.save(reply)
    }
}
